package org.aphasia4j.dao.impl;

import java.util.List;

import org.aphasia4j.dao.TaskDao;
import org.aphasia4j.dao.core.BaseDaoSupport;
import org.aphasia4j.model.Patient;
import org.aphasia4j.model.Task;

/**
 * Implementation of the {@link TaskDao} interface description.
 * 
 * @author hillger.t
 */
public class TaskDaoImpl extends BaseDaoSupport<Task> implements TaskDao {

  @Override
  public List<Task> findByPatient(Patient patient) {
    return findByPatient(patient.getId());
  }

  @Override
  @SuppressWarnings("unchecked")
  public List<Task> findByPatient(long patientId) {
    String jql = "select t from Task t where t.patient.id = ?";
    return getJpaTemplate().find(jql, patientId);
  }

  @Override
  @SuppressWarnings("unchecked")
  public List<Task> findByPatientName(String namePart) {
    String jql = "select t from Task t where lower(t.patient.lastname) like ?";
    return getJpaTemplate().find(jql, namePart.toLowerCase() + "%");
  }
}
